package com.wlstock.funi.receiver;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import com.wlstock.funi.constant.ServiceConstants;
import com.wlstock.funi.service.LatestPriceService;
import com.wlstock.funi.utils.ServiceUtil;

public class AutoReceiver extends BroadcastReceiver {

    //static final String ACTION = "android.intent.action.BOOT_COMPLETED";
	private static final int MODE_PRIVATE = 0;
	private Context mContext;
    @Override
    public void onReceive(Context context, Intent intent) 
    {

    	mContext = context;
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.i("BootBroadcastReceiver", "BroadcastReceiver onReceive here.... ");
            Handler handler = new Handler(Looper.getMainLooper());
            //after reboot the device,about 2 minutes later,upload the POI info to server
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                	Toast.makeText(mContext, "Receiver AutoReceiver", 500).show();
                	//追踪操盘手的service
                    if(!ServiceUtil.isServiceRunning(mContext,ServiceConstants.TIMER_SERVICE)){
                        ServiceUtil.invokeTrackService(mContext);
                    }
                    //更新股票池行情的service
                    if (!ServiceUtil.isServiceRunning(mContext, LatestPriceService.class.getName())) {
						ServiceUtil.invokeService(mContext, LatestPriceService.class, ServiceConstants.LatestPriceService_ACTION_START,ServiceConstants.ELAPSED_TIME_UPDATE_PPICE);
					}
                }
            }, ServiceConstants.BROADCAST_ELAPSED_TIME_DELAY);
        }
    }

}
